//
//  SRBookPageSettingView.m
//  StoryShow
//
//  Created by CyonLeuMBP on 2017/4/19.
//  Copyright © 2017年 qudiandu.cn. All rights reserved.
//

#import "SRBookPageSettingView.h"

@interface SRBookPageSettingView ()

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *speedPreLabel;
@property (weak, nonatomic) IBOutlet UILabel *clickAreaShowPreLabel;
@property (weak, nonatomic) IBOutlet UILabel *showTranslatePreLabel;
@property (weak, nonatomic) IBOutlet UILabel *lowSpeedLabel;
@property (weak, nonatomic) IBOutlet UILabel *normalSpeedLabel;
@property (weak, nonatomic) IBOutlet UILabel *highSpeedLabel;

@property (weak, nonatomic) IBOutlet UISlider *speedSlider;
@property (weak, nonatomic) IBOutlet UISwitch *clickAreaShowSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *showTranslateSwitch;

@end

@implementation SRBookPageSettingView


- (void)awakeFromNib {
    [super awakeFromNib];
    
    FZStyleSheet *css = [FZStyleSheet currentStyleSheet];
    
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
    self.titleLabel.textColor = css.color_4;
    self.titleLabel.font = css.fontOfH2;
    
    self.speedPreLabel.textColor = self.clickAreaShowPreLabel.textColor = self.showTranslatePreLabel.textColor = css.color_4;
    
    self.speedPreLabel.font = self.clickAreaShowPreLabel.font = self.showTranslatePreLabel.font = css.fontOfH4;

    self.lowSpeedLabel.textColor = self.normalSpeedLabel.textColor = self.highSpeedLabel.textColor = css.color_4;
    self.lowSpeedLabel.font = self.normalSpeedLabel.font = self.highSpeedLabel.font = css.fontOfH4;
    
    self.speedSlider.minimumTrackTintColor = css.color_4;
    self.speedSlider.maximumTrackTintColor = css.color_4;
    self.speedSlider.thumbTintColor = css.color_7;
    
    if (self.audioRate > 0) {
        [self.speedSlider setValue:self.audioRate];
    }
}

- (void)setAudioRate:(CGFloat)audioRate {
    _audioRate = audioRate;
    
    [self.speedSlider setValue:self.audioRate];
}

- (IBAction)onSpeedSliderValueChanged:(UISlider *)slider {
    NSLog(@"***********onSpeedSliderValueChanged:%f", slider.value);
    CGFloat audioSpeed = slider.value;
    if (audioSpeed <= 0.8) {
        audioSpeed = 0.5;
    } else if (audioSpeed > 0.8 && audioSpeed < 1.4){
        audioSpeed = 1.0;
    } else if (audioSpeed >= 1.4){
        audioSpeed = 2.0;
    }
    
    if (self.speedValueDidChangeBlock) {
        self.speedValueDidChangeBlock(audioSpeed);
    }
}

- (IBAction)onClickAreaShowValueChanged:(UISwitch *)showSwitch {
    if (self.clickAreaShowValueDidChangeBlock) {
        self.clickAreaShowValueDidChangeBlock(showSwitch.isOn);
    }
}

- (IBAction)onShowTranslateValueChanged:(UISwitch *)showSwitch {
    if (self.showTranslateValueDidChangeBlock) {
        self.showTranslateValueDidChangeBlock(showSwitch.isOn);
    }
}

@end
